﻿using System;
using Volo.Abp.Validation.StringValues;

namespace Xms.Abp.Validation.StringValues;

[Serializable]
[StringValueType("TEXT")]
public class TextValueValidator : ValueValidatorBase
{
    public int MaxLength
    {
        get => (this[nameof(MaxLength)] ?? "128").To<int>();
        set => this[nameof(MaxLength)] = value;
    }
    public TextValueValidator()
    {
        MaxLength = 128;
    }
    public TextValueValidator(int maxLength)
    {
        MaxLength = maxLength;
    }
    public override bool IsValid(object value)
    {
        if (value != null && value is string str && str.Length <= MaxLength)
        {
            return true;
        }
        return false;
    }
}
